//
//  CellForSPWorld.m
//  StayAwhile
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForSPWorld.h"
#import "TXPSPWorld.h"
#import "TXPLBfit.h"
@interface CellForSPWorld ()
@property(nonatomic,strong)UILabel *nameLaber;
@property(nonatomic,strong)UILabel *titleLaber;
@property(nonatomic,strong)UIImageView *coverimgView;
@property(nonatomic,strong)UILabel *contentLaber;
@property(nonatomic,strong)UILabel *likeLabel;
@property(nonatomic,strong)UIImageView *likeView;
@end

@implementation CellForSPWorld

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    [self createSubview];
    }
    return self;
}


-(void)createSubview{
    self.nameLaber =[[UILabel alloc] initWithFrame:CGRectMake(15, 10, WIDTH - 20, 20)];
    self.nameLaber.font = [UIFont systemFontOfSize:13];
    self.nameLaber.textColor = [UIColor grayColor];
    self.coverimgView =[[UIImageView alloc] initWithFrame:CGRectMake(30, 35, WIDTH -60, 150)];
    self.titleLaber =[[UILabel alloc]initWithFrame:CGRectMake(15, 190, WIDTH -30, 20)];
    self.contentLaber =[[UILabel alloc] initWithFrame:CGRectMake(15, 210, WIDTH - 30, 50)];
    self.contentLaber.font = [UIFont systemFontOfSize:15];
    self.contentLaber.textColor = [UIColor darkGrayColor];
    self.contentLaber.numberOfLines = 0;
    
//    self.likeLabel =[[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 50, 260, 50, 20)];
    
    
    self.likeLabel = [[UILabel alloc]init];
    self.likeLabel.font = [UIFont systemFontOfSize:13];
    self.likeLabel.textColor = [UIColor grayColor];
    self.likeView =[[UIImageView alloc]init];
    self.likeView.image =[UIImage imageNamed:@"iconfont-shoucangweishoucang"];
    [self.contentView addSubview:self.likeView];
    [self.contentView addSubview:self.nameLaber];
    [self.contentView addSubview:self.coverimgView];
    [self.contentView addSubview:self.titleLaber];
    [self.contentView addSubview:self.contentLaber];
    [self.contentView addSubview:self.likeLabel];
    self.contentView.frame =CGRectMake(0, 0, WIDTH, 400);
    
}

-(void)setBaseModel:(TXPSPBaseModel *)baseModel{
    [super setBaseModel:baseModel];
    TXPSPWorld *world =(TXPSPWorld *)baseModel;
    NSString *str =[world.name stringByAppendingString:@" · "];
    NSString *strone =[str stringByAppendingString:world.enname];
    self.nameLaber.text = strone;
    
    self.titleLaber.text = world.title;
    self.contentLaber.text = world.content;
 
    [self.coverimgView sd_setImageWithURL: [NSURL URLWithString:world.coverimg]placeholderImage:nil];
    CGFloat heightcont  = [TXPLBfit heightForContents:self.contentLaber.text Nsnumber:15];
    if (heightcont >= 89.50) {
        heightcont = 89.50;
    }
    CGRect framecon = self.contentLaber.frame;
    framecon.size.height = heightcont;
    self.contentLaber.frame = framecon;
   
    
    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentLaber.mas_bottom).offset(0);
        make.right.mas_equalTo( WIDTH - 20);
        make.left.mas_equalTo(WIDTH-50);
        make.height.mas_equalTo(20);
        
    }];
    NSString *like =[NSString stringWithFormat:@"%ld",world.like];
    self.likeLabel.text = like;
    [self.likeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentLaber.mas_bottom).offset(0);
        make.right.mas_equalTo(self.likeLabel.mas_left).offset(0);
        make.left.mas_equalTo(WIDTH - 70);
        make.height.mas_equalTo(17);
        
    }];
    
    
}



@end
